package com.acme.bankapp.domain.bank;

import com.acme.bankapp.domain.bank.*;

public class CheckingAccount implements Account{

	private int balance;
	private int overdraft = 30;
	
	// TODO: [VY] Ok. But lowercase next time please ;)
	private int Id;
	
	public CheckingAccount(int balance, int id){
		this.balance = balance;
		this.Id=id;
	}

	@Override
	public int hashCode() {
		return Id;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj) return true;
		if (obj == null) return false;
		if (getClass() != obj.getClass()) return false;
		AbstractAccount other = (AbstractAccount) obj;
		if (Id != other.Id) return false;
		return true;
	}
	
	@Override
	public int getBalance() {
		return balance;
	}

	@Override
	public void deposit(double x) {
		balance += x;
	}

	@Override
	public void withdraw(double x) throws OverdraftLimitExceededException {
		if(x <= balance){
			balance -= x;
		}
		else
		{
			x -= balance;
			if(x <= overdraft){
				overdraft -= x;
				System.out.println("You recieved a credit: " + x);
			}
			else{
				throw new OverdraftLimitExceededException(balance+overdraft);
			}
		}
	}

	@Override
	public double maximumAmountToWithdraw() {
		return balance+overdraft;
	}

	@Override
	public int decimalValue() {
		return(Math.round(balance));
	}
}
